package ACWing.DataStructure.队列;
//829. 模拟队列

import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/12/28 16:39
 */
public class AnalogQueue {
    static int[]q=new int[100010];
    static int tt=-1;//尾
    static int hh;//头
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int m=sc.nextInt();
        sc.nextLine();
        while (m-->0){
            String s=sc.next();
            if("push".equals(s)){
                int x=sc.nextInt();
                push(x);
            }
            if("pop".equals(s)){
                if(!empty()){
                    pop();
                }
            }
            if("empty".equals(s)){
                if(empty()){
                    System.out.println("YES");
                }else {
                    System.out.println("NO");
                }
            }
            if("query".equals(s)){
                if(!empty()){
                    System.out.println(query());
                }
            }
        }
    }
    public static void push(int x){
        q[++tt]=x;
    }
    public static void pop(){
        hh++;
    }
    public static boolean empty(){
        if(hh<=tt){
            return false;
        }
        return true;
    }
    public static int query(){
        int n=q[hh];
        return n;
    }

}
